package com.tacc.tyun.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import com.tacc.tyun.base.BaseServiceImpl;
import com.tacc.tyun.dao.master.WxMenuDao;
import com.tacc.tyun.model.WxMenu;
import com.tacc.tyun.service.WxMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-04-19 14:11
 **/
@Service("WxMenuService")
public class WxMenuServiceImpl extends BaseServiceImpl<WxMenu> implements WxMenuService {
    @Resource
    private WxMenuDao wxMenuDao;
    @Autowired
    public void setWxMenuDao(WxMenuDao wxMenuDao) {
        this.baseDao = wxMenuDao;
    }

    //分页查询
    public PageInfo<WxMenu> pageInfo(WxMenu wxMenu, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy(" sort desc");
        //通用Example查询
        Example example = new Example(WxMenu.class);
        if(wxMenu!=null){
            Example.Criteria criteria=example.createCriteria();
           if(wxMenu.getParentId() > 0){
               criteria.andEqualTo("parentId",wxMenu.getParentId());
           }
           if(StringUtil.isNotEmpty(wxMenu.getGrade())){
               criteria.andEqualTo("grade",wxMenu.getGrade());
           }
        }
        List<WxMenu> list=wxMenuDao.selectByExample(example);
        return new PageInfo<WxMenu>(list);
    }
    //条件查询
    public List<WxMenu> list(WxMenu wxMenu) {
        Example example = new Example(WxMenu.class);
        if(wxMenu!=null){
            Example.Criteria criteria=example.createCriteria();
            if(wxMenu.getParentId() > 0){
                criteria.andEqualTo("parentId",wxMenu.getParentId());
            }
            if(StringUtil.isNotEmpty(wxMenu.getGrade())){
                criteria.andEqualTo("grade",wxMenu.getGrade());
            }
        }
        example.setOrderByClause(" sort desc ");
        List<WxMenu> list=wxMenuDao.selectByExample(example);
        return list;
    }

}
